package com.itheima;
//懒汉式：不随着类的创建而创建对象，调用getInstance方法先做判断，如果该对象为空，则再创建对象
public class Singleton2 {
    private static Singleton2 singleton2 = null;

    private Singleton2() {

    }

    public static synchronized Singleton2 getInstance() {
        //对象为空，说明没创建
        if (singleton2 == null) {
            singleton2 = new Singleton2();
        }
        return singleton2;
    }

    @Override
    public String toString() {
        return "我是懒汉式";
    }
}
